package com.inspire.tank.cor;

import com.inspire.tank.Bullet;
import com.inspire.tank.GameObject;
import com.inspire.tank.Tank;
import com.inspire.tank.Wall;

/**
 * @author inspire
 * @description 计算坦克和墙相撞
 * @date 2022/6/15 23:01
 */
public class TankWallCollider implements Collider {
    @Override
    public boolean collide(GameObject gameObject1, GameObject gameObject2) {

        if (gameObject1 instanceof Tank && gameObject2 instanceof Wall) {
            Tank tank = (Tank) gameObject1;
            Wall wall = (Wall) gameObject2;

            if(tank.rect.intersects(wall.rect)){

                tank.back();
                return true;//墙还得继续和其他子弹撞击
            }
        } else if (gameObject1 instanceof Wall && gameObject2 instanceof Tank) {
            return collide(gameObject2, gameObject1);
        }
        return true;


    }
}
